package com.kidfit.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class KidFit2 extends LayoutContainer implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
//	private static final String SERVER_ERROR = "An error occurred while "
//			+ "attempting to contact the server. Please check your network "
//			+ "connection and try again.";

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
//	private final GreetingServiceAsync greetingService = GWT
//			.create(GreetingService.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		RootPanel.get().add(this);
	}
	
	@Override
	protected void onRender(Element parent, int pos) {
//		super.setSize(300, 300);
		super.onRender(parent, pos);
		parent.getStyle().setProperty("background", "#ffcc66");
		setLayout(new ColumnLayout());
		
		List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
		
		ColumnConfig column = new ColumnConfig();
		column.setId("rank");
		column.setHeader("Rank");
		column.setWidth(100);
		configs.add(column);
		
		column = new ColumnConfig();
		column.setId("name");
		column.setHeader("Name");
		column.setWidth(100);
		configs.add(column);
		
		column = new ColumnConfig();
		column.setId("points");
		column.setHeader("Total Points");
		column.setWidth(100);
		configs.add(column);
		
		column = new ColumnConfig();
		column.setId("time");
		column.setHeader("Total Time");
		column.setWidth(100);
		configs.add(column);
		
		column = new ColumnConfig();
		column.setId("today");
		column.setHeader("Today's Points");
		column.setWidth(100);
		configs.add(column);
		
		column = new ColumnConfig();
		column.setId("level");
		column.setHeader("Level");
		column.setWidth(100);
		configs.add(column);
		
		ColumnModel cm = new ColumnModel(configs);
		
		ListStore<Child> store = new ListStore<Child>();
		store.add(TestData.getChildren());
		
		ContentPanel cp = new ContentPanel();
		cp.setBodyBorder(false);
		cp.setHeading("Leader Board");
		cp.setButtonAlign(HorizontalAlignment.CENTER);
		cp.setLayout(new FitLayout());
		cp.setSize(600, 155);
		
		Grid<Child> grid = new Grid<Child>(store, cm);
		grid.setStyleAttribute("bordertop", "none");
		grid.setAutoExpandColumn("name");
		grid.setBorders(true);
		grid.setStripeRows(true);
		cp.add(grid);
		
		final Image image = new Image();
		image.setUrl("http://www.amh.org/img/logo/child-growth.gif");
		
		VerticalPanel vPanel = new VerticalPanel();
		vPanel.add(image);
		vPanel.setTableWidth("100");
		
		add(vPanel, new ColumnData(100));
		add(cp, new ColumnData(600));
		
		
	}
}
